const {
  post
} = require('../../utils/http')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword: '',
    datalist: [],
    historylist: wx.getStorageSync('historylist')||[],
    showHistory: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.handleSearch()
  },
  inpuntChange(event) {
    this.setData({
      keyword: event.detail.value
    })
  },
  async handleSearch() {
    let historylist = wx.getStorageSync('historylist') || [];
    historylist.push(this.data.keyword)
    let list = [...new Set(historylist)]
    wx.setStorageSync('historylist', list)
    this.setData({
      showHistory: false
    })
    wx.showLoading()
    let rs = await post('index.php/trade/get_search_list', {
      keyword: this.data.keyword
    })
    console.log(rs);
    this.setData({
      datalist: rs.data
    })
    wx.hideLoading()
  },
  searchByHistory(event) {
    this.setData({
      keyword: event.currentTarget.dataset.keyword
    })
    this.handleSearch();
  },

  goDetail(event){
    let id = event.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+id,
    })
  }



})